package cn.zyq.charging.common.pojo;

import lombok.AccessLevel;
import lombok.Data;
import lombok.experimental.FieldDefaults;

/**给view统一返回结果*/
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
//用来设置字段的默认访问级别(访问级别默认是private)
//可以省略属性的访问权限
public class JsonResult<T> {

    /***
     * 状态码
     */
    private Integer code;
    /***
     * 状态码对应的消息
     */
    private String message;
    /***
     * 返回的数据
     */
    private T data;
    public JsonResult() {
    }
    public JsonResult(Integer code, String msg, T data) {
        this.code = code;
        this.message = msg;
        this.data = data;
    }
    public JsonResult(Integer code, String msg) {
        this.code = code;
        this.message=msg;
    }
    public JsonResult(Integer code) {
        this.code = code;
    }
    public JsonResult(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    /**
     * 正常返回 。
     * 入参： 有数据状态码和消息
     * @param data
     * @param msg
     * @return
     */
    public static JsonResult ok(Object data,String msg) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(data);
        jsonResult.setCode(2000);
        jsonResult.setMessage(msg);
        return jsonResult;
    }

    /**
     * 正常返回
     * 入参： 只有数据
     * @param data
     * @return
     */
    public static JsonResult ok(Object data) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(data);
        jsonResult.setCode(2000);
        return jsonResult;
    }

}
